package com.macro.mall.service.impl;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.macro.mall.dto.BmsConfigParam;
import com.macro.mall.mapper.BmsConfigMapper;
import com.macro.mall.model.BmsConfig;
import com.macro.mall.service.BmsConfigService;
import com.macro.mall.utils.AdminUtils;

/**
 * 商品属性管理Service实现类 Created by macro on 2018/4/26.
 */
@Service
public class BmsConfigServiceImpl implements BmsConfigService {

    @Autowired
    private BmsConfigMapper baseMapper;

    @Override
    public BmsConfig getList(BmsConfigParam bmsConfigParam) {
        return baseMapper.getByCode(bmsConfigParam.getCode());
    }

    @Override
    public String getValueByCode(String code) {
        return baseMapper.getValueByCode(code);
    }

    @Override
    public BmsConfig getByCode(String code) {
        return baseMapper.getByCode(code);
    }

    @Transactional
    @Override
    public void create(BmsConfigParam param) {
        BmsConfig entity = new BmsConfig();
        BeanUtils.copyProperties(param, entity);
        AdminUtils.setCreation(entity);
        baseMapper.create(entity);
    }

    @Transactional
    @Override
    public void update(BmsConfigParam param) {
        BmsConfig entity = baseMapper.getById(param.getId());
        BeanUtils.copyProperties(param, entity);
        AdminUtils.setEdition(entity);
        baseMapper.update(entity);
    }

}
